<template>
  <div class="category-container">
    <div class="category-header">
      <h1>{{ category.name }}</h1>
      <div class="category-actions">
        <button class="new-post-btn" @click="createPost">
          <i class="fas fa-plus"></i>
          发布新帖
        </button>
      </div>
    </div>

    <div class="filter-bar">
      <div class="filter-left">
        <select v-model="sortBy" class="sort-select">
          <option value="latest">最新发布</option>
          <option value="hot">最热门</option>
          <option value="comments">最多评论</option>
        </select>
      </div>
      <div class="filter-right">
        <div class="view-mode">
          <button 
            class="view-btn" 
            :class="{ active: viewMode === 'list' }"
            @click="viewMode = 'list'"
          >
            <i class="fas fa-list"></i>
          </button>
          <button 
            class="view-btn" 
            :class="{ active: viewMode === 'grid' }"
            @click="viewMode = 'grid'"
          >
            <i class="fas fa-th-large"></i>
          </button>
        </div>
      </div>
    </div>

    <div class="posts-container" :class="viewMode">
      <div v-for="post in posts" :key="post.id" class="post-card">
        <div class="post-header">
          <div class="post-badges">
            <span v-if="post.isTop" class="badge top">置顶</span>
            <span v-if="post.isEssence" class="badge essence">精华</span>
          </div>
          <h2 class="post-title">
            <router-link :to="`/forum/post/${post.id}`">{{ post.title }}</router-link>
          </h2>
        </div>
        
        <div class="post-content">
          <p class="post-excerpt">{{ post.excerpt }}</p>
          <div class="post-tags">
            <span v-for="tag in post.tags" :key="tag" class="tag">{{ tag }}</span>
          </div>
        </div>

        <div class="post-footer">
          <div class="post-meta">
            <router-link :to="`/user/${post.author.id}`" class="author">
              <img :src="post.author.avatar" :alt="post.author.name">
              <span>{{ post.author.name }}</span>
            </router-link>
            <span class="time">{{ post.createTime }}</span>
          </div>
          <div class="post-stats">
            <span class="stat">
              <i class="fas fa-eye"></i>
              {{ post.views }}
            </span>
            <span class="stat">
              <i class="fas fa-comment"></i>
              {{ post.comments }}
            </span>
            <span class="stat">
              <i class="fas fa-heart"></i>
              {{ post.likes }}
            </span>
          </div>
        </div>
      </div>
    </div>

    <div class="pagination">
      <button 
        class="page-btn" 
        :disabled="currentPage === 1"
        @click="currentPage--"
      >
        上一页
      </button>
      <span class="page-info">{{ currentPage }} / {{ totalPages }}</span>
      <button 
        class="page-btn" 
        :disabled="currentPage === totalPages"
        @click="currentPage++"
      >
        下一页
      </button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'

const route = useRoute()
const category = ref({
  id: 1,
  name: '游戏攻略'
})

const sortBy = ref('latest')
const viewMode = ref('list')
const currentPage = ref(1)
const totalPages = ref(10)

// 模拟帖子数据
const posts = ref([
  {
    id: 1,
    title: '新手入门攻略',
    excerpt: '这是一篇详细的新手入门攻略，包含了游戏基础操作、角色培养等内容...',
    author: {
      id: 1,
      name: '游戏达人',
      avatar: '/avatars/user1.jpg'
    },
    createTime: '2024-03-15 14:30',
    views: 1234,
    comments: 56,
    likes: 78,
    isTop: true,
    isEssence: true,
    tags: ['新手', '攻略', '入门']
  }
])

const createPost = () => {
  // TODO: 实现发帖功能
}

onMounted(() => {
  // TODO: 加载分类数据
  // TODO: 加载帖子列表
})
</script>

<style scoped>
.category-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.category-header h1 {
  margin: 0;
  color: #2c3e50;
}

.new-post-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.8rem 1.5rem;
  background-color: #42b983;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}

.filter-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding: 1rem;
  background: #f5f5f5;
  border-radius: 4px;
}

.sort-select {
  padding: 0.5rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
}

.view-mode {
  display: flex;
  gap: 0.5rem;
}

.view-btn {
  padding: 0.5rem;
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
}

.view-btn.active {
  background: #42b983;
  color: white;
  border-color: #42b983;
}

.posts-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.posts-container.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}

.post-card {
  background: white;
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.post-header {
  margin-bottom: 1rem;
}

.post-badges {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.badge {
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.9rem;
}

.badge.top {
  background: #ff6b6b;
  color: white;
}

.badge.essence {
  background: #ffd93d;
  color: #2c3e50;
}

.post-title {
  margin: 0;
  font-size: 1.2rem;
}

.post-title a {
  color: #2c3e50;
  text-decoration: none;
}

.post-content {
  margin-bottom: 1rem;
}

.post-excerpt {
  color: #666;
  margin: 0 0 1rem;
  line-height: 1.6;
}

.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag {
  padding: 0.2rem 0.5rem;
  background: #f5f5f5;
  border-radius: 4px;
  font-size: 0.9rem;
  color: #666;
}

.post-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 1rem;
  border-top: 1px solid #eee;
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.author {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: #2c3e50;
}

.author img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
}

.time {
  color: #666;
  font-size: 0.9rem;
}

.post-stats {
  display: flex;
  gap: 1rem;
}

.stat {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  color: #666;
  font-size: 0.9rem;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-top: 2rem;
}

.page-btn {
  padding: 0.5rem 1rem;
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
}

.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.page-info {
  color: #666;
}
</style> 